package com.supergo.manager.controller;

import com.supergo.http.HttpResult;
import com.supergo.manager.service.BrandService;
import com.supergo.page.PageResult;
import com.supergo.pojo.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Classname BrandController
 * @Description TODO
 * @Date 2020/10/26 13:41
 * @Created by ccc-j
 * @email ccc-ju@outlook.com
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @PostMapping(value = "/query/{page}/{rows}")
    public HttpResult findPage(@RequestBody Brand brand,
                               @PathVariable Integer page,
                               @PathVariable Integer rows){
        try{
            PageResult result = brandService.findPage(page, rows, brand);
            return HttpResult.ok(result);
        }catch (Exception e){
            e.printStackTrace();
            return HttpResult.error();
        }
    }

    @RequestMapping(value = "/{brandId}")
    public Brand getBrandByid(@PathVariable Long brandId){
        Brand brand = brandService.findOne(brandId);
        return brand;
    }

}
